<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>验证码</title>
    <style>
        span{
            display: block;
            width: 120px;
            height: 20px;
            background-color: gray;
            text-align: center;
            color: red;
        }
    </style>
</head>
<body>
    <span id="code"></span>
    <input type="text" name="" id="user_code">
    <button id="submit">验证</button>
    <script>
        function random(min,max){
            return Math.floor(Math.random() * (max-min) + min);
        }
        function creatCode(){
            var code = '';
            var codeLength = 4;
            var ran = [0,1,2,3,4,5,6,7,8,9,
            'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
            for(var i=0;i<codeLength;i++){
                code = code + ran[random(0,36)];
            }
            return code;
        }
        var code = creatCode()
        var span_obj = document.getElementById('code')
        var input_obj = document.getElementById('user_code')
        var sub_obj = document.getElementById('submit')
        input_obj.onfocus = function(){
            span_obj.innerHTML = code
        }
        sub_obj.onclick = function(){
            // console.log(input_obj.value)
            if(input_obj.value === code){
                alert('验证成功，正在跳转')
                location.href = 'https://www.apeland.cn/'
            }else{
                alert('错误')
                location.reload()
            }
        }


    </script>
</body>
</html>